﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TSL.AjaxResult.KaiJiang
{
    public class KaiJiang5
    {
        public static int BDWD(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            string _temp = "";
            int win = 0;
            int ind = -1;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                string mycodes = mycode[i].ToString().Trim();
                for (int j = 0; j < 3; j++)
                {
                    _code = code[j].ToString().Trim();
                    ind = _temp.IndexOf(_code);
                    _temp = _temp + _code.ToString();
                    if ((mycodes.IndexOf(_code) != -1) && (ind < 0))
                    {
                        win++;
                    }
                }
                winbonus += win;
            }
            return winbonus;
        }

        public static int DaXiaoDS(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            string _mycode = string.Empty;
            int win = 0;
            int winbonus = 0;
            int DX = 9;
            int DS = 9;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                winbonus = 0;
                string[] mycodes = mycode[i].Split(new char[] { ',' });
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j + 3].ToString().Trim();
                    if (Convert.ToInt32(_code) > 5)
                    {
                        DX = 1;
                    }
                    else
                    {
                        DX = 0;
                    }
                    if ((Convert.ToInt32(_code) % 2) == 0)
                    {
                        DS = 2;
                    }
                    else
                    {
                        DS = 3;
                    }
                    _mycode = mycodes[j].ToString().Trim();
                    if (((_mycode.IndexOf(DX.ToString()) != -1) || (_mycode.IndexOf(DS.ToString()) != -1)) && (mycodes.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus += win;
                }
            }
            return winbonus;
        }

        public static int DWD(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                string[] mycodes = mycode[i].Split(new char[] { ',' });
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycodes[j].ToString().Trim().IndexOf(_code) != -1) && (mycodes.Length == 3))
                    {
                        win++;
                    }
                }
                winbonus += win;
            }
            return winbonus;
        }

        public static int HouErZUE(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                mycodes = mycode[i].ToString().Trim();
                for (int j = 0; j < 2; j++)
                {
                    _code = code[j + 2].ToString().Trim();
                    if (mycodes.IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int HouErZX(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode1 = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode1.Length; i++)
            {
                win = 0;
                string[] mycode3 = mycode1[i].ToString().Trim().Split(new char[] { ',' });
                for (int j = 0; j < mycode3.Length; j++)
                {
                    _code = code[j + 1].ToString().Trim();
                    if ((mycode3[j].ToString().Trim().IndexOf(_code) != -1) && (mycode3.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int HouErZXD(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                mycodes = mycode[i].ToString();
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j + 3].ToString().Trim();
                    if ((mycodes.Substring(j, 1).IndexOf(_code) != -1) && (mycodes.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int HouYiZX(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                winbonus = 0;
                string[] mycodes = mycode[i].Split(new char[] { ',' });
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j + 4].ToString().Trim();
                    if ((mycodes[j].ToString().Trim().IndexOf(_code) != -1) && (mycodes.Length == 1))
                    {
                        win++;
                    }
                }
                if (win == 1)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int OpenJJ(string caipiao_name, string codes, string buycodes)
        {
            switch (caipiao_name)
            {
                case "三星直选复式":
                    return SanXingZX(codes, buycodes);

                case "三星直选单式":
                    return SanXingZXD(codes, buycodes);

                case "前二直选复式":
                    return QianErZX(codes, buycodes);

                case "前二直选单式":
                    return QianErZXD(codes, buycodes);

                case "前一直选":
                    return QianYiZX(codes, buycodes);

                case "后二直选复式":
                    return HouErZX(codes, buycodes);

                case "后二直选单式":
                    return HouErZXD(codes, buycodes);

                case "后一直选":
                    return HouYiZX(codes, buycodes);

                case "三星组三":
                    return SanXingZUS(codes, buycodes);

                case "三星组六":
                    return SanXingZUL(codes, buycodes);

                case "前二组二":
                    return QianErZUE(codes, buycodes);

                case "后二组二":
                    return HouErZUE(codes, buycodes);

                case "不定位胆":
                    return BDWD(codes, buycodes);

                case "定位胆":
                    return DWD(codes, buycodes);
            }
            return 0;
        }

        public static int QianErZUE(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                mycodes = mycode[i].ToString().Trim();
                for (int j = 0; j < 2; j++)
                {
                    _code = code[j].ToString().Trim();
                    if (mycodes.IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int QianErZX(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode1 = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode1.Length; i++)
            {
                win = 0;
                string[] mycode3 = mycode1[i].ToString().Trim().Split(new char[] { ',' });
                for (int j = 0; j < mycode3.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycode3[j].ToString().Trim().IndexOf(_code) != -1) && (mycode3.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int QianErZXD(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                mycodes = mycode[i].ToString();
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycodes.Substring(j, 1).IndexOf(_code) != -1) && (mycodes.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int QianYiZX(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                winbonus = 0;
                string[] mycodes = mycode[i].Split(new char[] { ',' });
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycodes[j].ToString().Trim().IndexOf(_code) != -1) && (mycodes.Length == 1))
                    {
                        win++;
                    }
                }
                if (win == 1)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int SanXingZUL(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            bool zuliu = false;
            int win = 0;
            int winbonus = 0;
            if (((code[0] != code[1]) && (code[1] != code[2])) && (code[0] != code[2]))
            {
                zuliu = true;
            }
            if (zuliu)
            {
                for (int i = 0; i < mycode.Length; i++)
                {
                    win = 0;
                    mycodes = mycode[i].ToString().Trim();
                    for (int j = 0; j < 3; j++)
                    {
                        _code = code[j].ToString().Trim();
                        if (mycodes.IndexOf(_code) != -1)
                        {
                            win++;
                        }
                    }
                    if (win == 3)
                    {
                        winbonus++;
                    }
                }
            }
            if (!zuliu)
            {
                winbonus = 0;
            }
            return winbonus;
        }

        public static int SanXingZUS(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            bool zuxuan = false;
            if (((Convert.ToInt32(code[2]) == Convert.ToInt32(code[0])) || (Convert.ToInt32(code[1]) == Convert.ToInt32(code[2]))) || (Convert.ToInt32(code[1]) == Convert.ToInt32(code[0])))
            {
                zuxuan = true;
            }
            if ((Convert.ToInt32(code[2]) == Convert.ToInt32(code[0])) && (Convert.ToInt32(code[2]) == Convert.ToInt32(code[1])))
            {
                zuxuan = false;
            }
            if (zuxuan)
            {
                for (int i = 0; i < mycode.Length; i++)
                {
                    win = 0;
                    mycodes = mycode[i].ToString().Trim();
                    for (int j = 0; j < 3; j++)
                    {
                        _code = code[j].ToString().Trim();
                        if (mycodes.IndexOf(_code) != -1)
                        {
                            win++;
                        }
                    }
                    if (win == 3)
                    {
                        winbonus++;
                    }
                }
            }
            return winbonus;
        }

        public static int SanXingZX(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode1 = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode1.Length; i++)
            {
                win = 0;
                string[] mycode3 = mycode1[i].ToString().Trim().Split(new char[] { ',' });
                for (int j = 0; j < mycode3.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycode3[j].ToString().Trim().IndexOf(_code) != -1) && (mycode3.Length == 3))
                    {
                        win++;
                    }
                }
                if (win == 3)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int SanXingZXD(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string mycodes = string.Empty;
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                mycodes = mycode[i].ToString();
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j].ToString().Trim();
                    if ((mycodes.Substring(j, 1).IndexOf(_code) != -1) && (mycodes.Length == 3))
                    {
                        win++;
                    }
                }
                if (win == 3)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }
    }

}
